| Conditions | 4 |
| Paths | 2 |
| Total Lines | 21 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import nError from './creator'; |
||
| 8 | export const parseFetchResponseError = async response => { |
||
| 9 | if (response.ok) { |
||
| 10 | return nError({ |
||
| 11 | category: CATEGORIES.FETCH_RESPONSE_OK, |
||
| 12 | status: response.status, |
||
| 13 | message: "it shouldn't be caught as exception, please check the code", |
||
| 14 | }); |
||
| 15 | } |
||
| 16 | |||
| 17 | const { status, headers } = response; |
||
| 18 | const contentType = headers.get('content-type'); |
||
| 19 | const parseMethod = |
||
| 20 | contentType && contentType.includes('application/json') ? 'json' : 'text'; |
||
| 21 | const message = await response[parseMethod](); // system Error would be thrown if it fails |
||
| 22 | return nError({ |
||
| 23 | category: CATEGORIES.FETCH_RESPONSE_ERROR, |
||
| 24 | status, |
||
| 25 | message, |
||
| 26 | contentType, |
||
| 27 | }); |
||
| 28 | }; |
||
| 29 | |||
| 47 |